package homework;

public class PerformanceTest {
    public static void main(String[] args) {
        final int COUNT = 100000;

        // String测试
        long start1 = System.currentTimeMillis();
        String s = "";
        for (int i = 0; i < COUNT; i++) {
            s += "a";
        }
        long end1 = System.currentTimeMillis();

        // StringBuilder测试
        long start2 = System.currentTimeMillis();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < COUNT; i++) {
            sb.append("a");
        }
        long end2 = System.currentTimeMillis();

        System.out.println("String拼接耗时: " + (end1 - start1) + "ms");
        System.out.println("StringBuilder拼接耗时: " + (end2 - start2) + "ms");
    }
}
